package com.example.ailiyuncloud.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ailiyuncloud.dto.CommodityDto;
import com.example.ailiyuncloud.dto.InventoryAddDto;
import com.example.ailiyuncloud.pojo.BaseResponseData;
import com.example.ailiyuncloud.pojo.Result;
import com.example.ailiyuncloud.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lqj
 * @Date: 2024/05/23/14:28
 * @Description:
 */
@RestController
@RequestMapping("/commodity")
public class CommodityController {


    @Autowired
    private CommodityService commodityService;

    @PostMapping("/add")
    public Result<String> AddCommodityController(@RequestBody List<CommodityDto> commodityDto) {
        return commodityService.addCommodityService(commodityDto);
    }

    @PostMapping("/query")
    public Result<?> QueryCommodityController(@RequestParam(defaultValue = "1") int pageNo,
                                              @RequestParam(defaultValue = "10") int pageSize, @RequestBody CommodityDto commodityDto) {
        Page<CommodityDto> page = new Page(pageNo, pageSize);
        return commodityService.QueryCommodityService(page, commodityDto);
    }

    @PostMapping("/inventoryAdd")
    public Result<?> inventoryAddServiceController(@RequestBody List<InventoryAddDto> inventoryAddDto) {
        return commodityService.inventoryAddService(inventoryAddDto);
    }
}
